#!/usr/bin/python
import Gnuplot
import math
from random import uniform as ran


def naive_ran():
	global idum
        m = 134456
        n = 8121
        k = 28411
        idum = (idum*n + k) % m
        ran = idum/float(m)
        return ran

def naive_uniform(a, b):
        return float(a) + float(b-a)*naive_ran()


def markov_naive(seed, delta, N):
	global idum
	idum = seed
	x, y = 1., 1. # initial position
	N_hits = 0
	record = []
	for i in range(1,N):
		del_x = naive_uniform(-delta, delta) 
		del_y = naive_uniform(-delta, delta)

		if abs(x+del_x) < 1. and abs(y+del_y) < 1.:
			# Don't move if out of range.
			x, y = x + del_x, y + del_y

		if x**2 + y**2 < 1.:
			# N_hits + 1 while the point is in the circle of x^2+y^2=1.
			N_hits += 1

		c_pi = N_hits * 4. / float(i)
		err = abs(math.pi - c_pi)/math.pi*100.
		if i%100 ==1:
			# record per 100 points
			record.append([i, err])

	return record

g = Gnuplot.Gnuplot()
g.xlabel('iter times')
g.ylabel('err (%)')
g.plot(markov_naive(123456, 0.3, 10000))

raw_input()
